<template>
    <div class="container" ref="containerRef">
        <div class="app-title">
            <h1>分镜大师</h1>
        </div>
        <div class="sheet-container">
            <ScriptInput v-model="jsonInput" :error="error" v-show="activeTab === 'script'" />
            <CardDisplay :parsedData="parsedData" v-show="activeTab === 'cards'" />
        </div>
        <div class="sheet-show-box">
            <div class="sheet-show-btn" :class="{ active: activeTab === 'script' }" @click="activeTab = 'script'">镜头脚本
            </div>
            <div class="sheet-show-btn" :class="{ active: activeTab === 'cards' }" @click="activeTab = 'cards'">界面展示
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

import ScriptInput from './ScriptInput.vue'
import CardDisplay from './CardDisplay.vue'

const jsonInput = ref('[]')
const error = ref(null)
const activeTab = ref('script')
let firstFlag = true;

const parsedData = computed(() => {
    try {
        const data = JSON.parse(jsonInput.value)
        if (data?.output?.length) {
            error.value = null
            if (firstFlag) {
                // activeTab.value = "cards";
                firstFlag = false;
            }
            return data.output
        }
        return []
    } catch (e) {
        // error.value = e.message
        error.value = "JSON格式化错误"
        return []
    }
})
</script>

<style>
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.app-title {
    text-align: center;
    margin: 2rem 0;
}

.app-title h1 {
    font-size: 4rem;
    background: linear-gradient(45deg, #2196F3, #1565C0);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.container .sheet-show-box {
    position: fixed;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sheet-show-btn {
    writing-mode: vertical-rl;
    text-orientation: upright;
    padding: 32px 12px;
    border: 2px solid #2196F3;
    border-radius: 30px;
    background: white;
    color: #2196F3;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(33, 150, 243, 0.2);
}

.sheet-show-btn:hover {
    background: #2196F3;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.sheet-show-btn:active {
    transform: translateY(0);
}

.sheet-show-btn.active {
    background: #1565C0;
    border-color: #1565C0;
    color: white;
}
</style>